﻿using DevelopTool.Forms.BaseForms;
using System;
using System.IO;
using System.Windows.Forms;

namespace DevelopTool.Forms.ToolForms
{
    /// <summary>
    /// 简易网页浏览器
    /// </summary>
    public partial class WebBrowserForm : BaseUIPage
    {
        private string filePath;

        /// <summary>
        /// 文件路径
        /// </summary>
        public string FilePath
        {
            get
            {
                return this.filePath;
            }
            set
            {
                this.filePath = value;
            }
        }

        public WebBrowserForm()
        {
            InitializeComponent();
        }

        private void WebBrowserForm_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.filePath) && File.Exists(this.filePath))
            {
                this.txtUrl.Text = this.filePath;
                this.miniblinkWebBrowserControl.Browser.LoadUri(this.filePath);
            }
        }

        private void btnGo_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtUrl.Text)) return;
            this.miniblinkWebBrowserControl.Browser.LoadUri(this.txtUrl.Text);
        }

        private void txtUrl_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                if (string.IsNullOrEmpty(this.txtUrl.Text)) return;
                this.miniblinkWebBrowserControl.Browser.LoadUri(this.txtUrl.Text);
            }
        }
    }
}
